﻿namespace ASB.CC.Web.EZVisit.View
{
    #region Using Directives

    using System;
    using System.Web;
    using System.Web.UI.WebControls;
    using ASBCC.Database.Entity;
    using ASBCC.Database.Service;
    using BEGDC.CC.BL.Common;
    using BEGDC.CC.BL.UserManagement;
    using BEGDC.CC.BL.Workflow;
    using BEGDC.CC.Web.Workflow;
    using BEGDC.Utility.Castle;

    #endregion

    public partial class MyProperty : BasePage
    {
        protected LinkButton LinkButton1;
        protected ImageButton btnDel1;
        protected Button btnSave;
        protected HiddenField hidGuid1;
        protected Label lblDateFrom1;
        protected Label lblDateTo1;
        protected Label lblDepartment;
        protected Label lblLogin;
        protected Label lblName;
        protected Label lblNameChinese;
        protected Label lblss1;

        private void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.GetUserInfo();

                UserDelegationTableEntitySet set1 = UserDelegationManager.SelectByCondition(string.Format("UserID = {0}", this.UserInfo.EmployeeID));
                if (set1.Count > 0)
                {
                    this.hidGuid1.Value = set1[0].UserDelegationID.ToString();
                    this.lblDateFrom1.Text = set1[0].FromDate + string.Empty;
                    this.lblDateTo1.Text = set1[0].ToDate + string.Empty;

                    EmployeeTableEntitySet set2 = EmployeeManager.SelectByCondition(string.Format("EmployeeID = {0}", set1[0].DelegateTo));
                    if (set2.Count > 0)
                    {
                        this.lblss1.Text = set2[0].NameEN;
                    }
                }
            }
        }

        private void GetUserInfo()
        {
            var userService = (IUser) AppContainer.Instance[ServiceConst.UserService];
            var employee = userService.GetUserByID(((CCIdentity) HttpContext.Current.User.Identity).UserInfo.Id);

            if (employee == null)
            {
                return;
            }

            this.lblLogin.Text = employee.NameEN;
            this.lblName.Text = employee.NameCN;
            this.lblNameChinese.Text = employee.NameChinese;
            this.lblDepartment.Text = employee.Department.DepartmentCode;
        }

        protected void btnDel1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hidGuid1.Value))
            {
                return;
            }

            UserDelegationManager.Delete(new Guid(this.hidGuid1.Value));
            this.lblss1.Text = string.Empty;
            this.lblDateFrom1.Text = string.Empty;
            this.lblDateTo1.Text = string.Empty;
        }

        #region Web Form Designer generated code

        protected override void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        ///   Required method for Designer support - do not modify
        ///   the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += this.Page_Load;
        }

        #endregion
    }
}